package demo4;

class Animal {
    public String name;
    public int age;

    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(this.name + "正在吃饭");
    }
}

interface IFly {
    void fly();
}
interface IRun {
    void run();
}
interface ISwim {
    void swim();
}

class Dog extends Animal implements IRun {
    public Dog(String name,int age) {
        super(name,age);
    }
    public void run() {
        System.out.println(this.name + "这只狗正在跑");
    }

    public void eat() {
        System.out.println(this.name + "正在吃狗粮");
    }
}

class Frog extends Animal implements IRun,ISwim {
    public Frog(String name,int age) {
        super(name,age);
    }
    public void run() {
        System.out.println(this.name + "这只青蛙正在跑");
    }
    public void swim() {
        System.out.println(this.name + "这只青蛙正在游泳");
    }

    public void eat() {
        System.out.println(this.name + "正在吃蛙粮");
    }
}

class Duck extends Animal implements IRun,IFly,ISwim {
    public Duck(String name,int age) {
        super(name,age);
    }
    public void run() {
        System.out.println(this.name + "这只鸭子正在跑");
    }
    public void swim() {
        System.out.println(this.name + "这只鸭子正在游泳");
    }
    public void fly() {
        System.out.println(this.name + "这只鸭子正在飞");
    }

    public void eat() {
        System.out.println(this.name + "正在吃鸭粮");
    }
}

public class Test {
    public static void func1(Animal animal) {
        animal.eat();
    }
    public static void running(IRun iRun) {
        iRun.run();
    }
    public static void flying(IFly iFly) {
        iFly.fly();
    }
    public static void swimming(ISwim iSwim) {
        iSwim.swim();
    }
    public static void main(String[] args) {
        running(new Duck("唐老鸭",1));
        running(new Dog("二狗子",2));
        running(new Frog("蛙",3));
    }
    public static void main1(String[] args) {
        func1(new Duck("唐老鸭",1));
        func1(new Dog("二狗子",2));
        func1(new Frog("蛙",3));
    }
}





